public class menu {
    private static Code code = new Code();
    //主菜单（改）（改2）me(改)
////////////////////
    public static void main(String[] args) {
        boolean loop = true;
        char chioce;
        while (loop) {
            System.out.println("==================================");
            System.out.println("\t\t欢迎使用密码管理系统");
            System.out.println("==================================");
            System.out.println("\t\t请选择操作：");
            System.out.println("\t\t1.加密");
            System.out.println("\t\t2.解密");
            System.out.println("\t\t3.判断密码强度");
            System.out.println("\t\t4.密码生成");
            System.out.println("\t\t5.退出");
            System.out.print("\t请输入：");
            chioce = MyUtility.readChar();
            switch (chioce) {
                case '1':
                    encryption();
                    break;
                case '2':
                    decrypt();
                    break;
                case '3':
                    strength();
                    break;
                case '4':
                    get_A_Code();
                    break;
                case '5':
                    loop = exit();
                    break;
                default:
                    System.out.println("输入错误");
            }
        }
    }

    //随机密码生成器
    private static void get_A_Code() {
        System.out.println("==================================");
        System.out.println("\t\t欢迎使用密码管理系统");
        System.out.println("==================================");
        System.out.println("随机强密码为");
        System.out.println(code.getCode());
        System.out.println("按任意键返回");
        MyUtility.readSting();
    }

    //判断密码强度
    private static void strength() {
        System.out.println("==================================");
        System.out.println("\t\t欢迎使用密码管理系统");
        System.out.println("==================================");
        System.out.print("请输入密码以判断强度");
        code.setCode(MyUtility.readCode());
        System.out.println("密码强度为：" + code.passwordStrength() + "强度");
        System.out.println("按任意键返回");
        MyUtility.readSting();
    }

    public static boolean exit(){
        char c=MyUtility.readChar();
        if(c=='y'){
            MyUtility.exit();
            return false;
        } else if (c=='n') {
            return true;
        }else {
            System.out.println("输入错误");
            return menu.exit();
        }
    }

    //加密界面
    private static void encryption() {
        System.out.println("==================================");
        System.out.println("\t\t欢迎使用密码管理系统");
        System.out.println("==================================");
        System.out.print("请输入要加密的数字密码：");
        code.setCode(MyUtility.readCode());
        System.out.print("加密后的结果是");
        System.out.println(code.codeEncryption());
        System.out.println("按任意键返回");
        MyUtility.readSting();
    }

    //解密界面
    private static void decrypt() {
        System.out.println("==================================");
        System.out.println("\t\t欢迎使用密码管理系统");
        System.out.println("==================================");
        System.out.print("请输入要解密的数字密码：");
        code.setCode(MyUtility.readCode());
        System.out.print("解密后的结果是");
        System.out.println(code.codeDecrypt());
        System.out.println("按任意键返回");
        MyUtility.readSting();
    }
}